package bavaria.hightech.banking;

import java.util.Calendar;
import bavaria.hightech.exception.WrongValueException;
import bavaria.hightech.timer.InternalClock;

/**
 * Implements the method of paying interest.
 * Positive account balances will be pay with credit interest, negative account balances
 * will be pay with debit interest. However, only a current account can have a negative account balance.
 * 
 * @author Christian Adler, Daniel Fuss;
 */
public class CurrentAccount extends Account {

	CurrentAccountConditions conditions;

	public CurrentAccount(int accountNumber, String depositor, CurrentAccountConditions conditions, Calendar starttime){
		super(accountNumber, depositor, starttime);
		this.conditions = conditions;
	}
	
	/**
	 * Implementation of the method of paying interest in order to realize positive and negative
	 * interest-paying
	 */
	@Override
	public void payInterest() throws WrongValueException{
		if(this.getAccountBalance() > 0){
			this.cashIn(new Money(this.getAccountBalance()*conditions.getCreditInterest(), this.getCurrency()), "verzinsung", InternalClock.getCalendar().getTime());
		} else {
			this.cashOut(new Money(this.getAccountBalance()*conditions.getDebitInterest(), this.getCurrency()) , "negativ verzinsung", InternalClock.getCalendar().getTime());
		}
	}
	
	public String toString(){
		String data = "Kontonummer: " + getAccountNumber() + "\n Kontentyp: Girokonto \n Kontoinhaber: " +
			getDepositor() + "\n Kontostand: " + getAccountBalance() + "\n Habenzinssatz: " + conditions.getCreditInterest()
			+ "\n Sollzinssatz: " + conditions.getDebitInterest();
		
		return data;
	}

}
